/* 
 * File:   Process.cpp
 * Author: James
 * 
 * Created on November 5, 2010, 9:49 PM
 */


#include "Process.h"


Process::Process() {
    cout << "generic constructor" << endl;
    p_id = 0;
    arrive = 0;
    burst = 0; 
    remaining = 0;
    last_exe = 0;
    io_time = 0; 
    io_completion = 0;
    priority = 0; 
    deadline = 0;
}
Process::Process(int pid, int bst, int arr, int pri, int dl, int io) {
    cout << "Creating process: " << pid << endl;
    p_id = pid;
    arrive = arr;
    burst = bst;
    remaining = bst;
    last_exe = arr;
    io_time = io;
    io_completion = -1; // negative one if not applicable
    priority = pri;
    deadline = dl;

}
Process::Process(const Process& orig) {
    cout << "Copy:" << p_id << endl;
    p_id = orig.p_id;
    arrive = orig.arrive;
    burst = orig.burst;
    remaining = orig.remaining;
    last_exe = orig.last_exe;
    io_time = orig.io_time;
    io_completion = orig.io_completion;
    priority = orig.priority;
    deadline = orig.deadline;

}

Process::~Process() {
    cout << "Deleting Process: " << p_id << endl;
}

// clock tick reduces remaining time
Process Process::operator-- () {
    this->remaining--;
}

void Process::tick() {
    this->remaining--;
}

void Process::initialize(int* args) {
    int i;
    /* prints stuff
    cout << "Init process: ";
    for (i = 0; i < 6; i++) {
        cout << args[i] << " ";
    }
    cout << endl;
    */
    p_id = args[0];
    arrive = args[1];
    burst = args[2];
    remaining = args[0];
    last_exe = args[1];
    io_time = args[3];
    io_completion = -1; // negative one if not applicable
    priority = args[4];
    deadline = args[5];
}
// last exe is set when a process is kicked from the CPU.
// the value is used to check for starving processes
void Process::setLastExe(int l) {
    this->last_exe = l;
}
// set when a process is kicked out for I/O, it will be returned to
// the ready queue when io_completion == clock value
// the IO wait queue should add in order based on I/O completion
void Process::setIOCompletion(int c) {
    this->io_completion = c;
}

bool Process::isDone() {
    // if time remaining is 0 or less, it's done.
    return (remaining < 1);
}

int Process::getID(void) {
    return this->p_id;
}
int Process::getArrive(void) {
    return this->arrive;
    }
int Process::getBurst(void) {
    return this->burst;
}

int Process::getRemaining(void) {
    return this->remaining;
}
/*
 * called when doing a HWS sweep to find a starving process
 */
int Process::getLastExe(void) {
    return this->last_exe;
}
/*
 * called to determine proirity for RTS
 */
int Process::getDeadline(void) {
    return this->deadline;
}
int Process::getIO(void) {
    return this->io_time;
}
int Process::getIOCompletion(void) {
    return this->io_completion;
}
int Process::getPriority(void) {
    return this->priority;
}
